// 一个常见的`webpack`配置文件
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

module.exports = {
  entry: {
    "index": __dirname + "/app/index.js"//已多次提及的唯一入口文件
  },
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: "[name].[chunkhash].js"
  },
  devServer: {
    contentBase: path.join(__dirname, "dist"),
    compress: true,
    port: 8088,
    host: "127.0.0.1",
  },
  mode:"development",//production
  module: {
    rules: [{
      test: /(\.jsx|\.js)$/,
      use: {
        loader: "babel-loader"
      },
      exclude: /node_modules/
    }, 
    {
      test: /\.css$/,
      use: [
        'style-loader',
        'css-loader'
      ],
      exclude: /node_modules/
    }]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: __dirname + "/app/index.html" //new 一个这个插件的实例，并传入相关的参数
    }),
    new CleanWebpackPlugin()
  ]
};